var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgList: [],
    overlayShow: false,
    signedShow: false,
    express_sn: "",
    deduct_love: "",
    basic_info: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    let basic_info = wx.getStorageSync('yz_basic_info') || {};
    this.setData({
      express_sn: options.express_sn,
      basic_info
    })
    this.getData();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  closeOverlayShow() {
    wx.navigateTo({
      url:  `/mircoApp/expressSignature/index/index`,
    });
  },
  clickBuyButton(ev) {
    wx.navigateTo({
      url:  ev.currentTarget.dataset.mini_link,
    });
  },
  successUp(event) {
    this.setData({
      imgList:event.detail.list,
    })
  },
  delete(event) {
    // this.setData({
    //   'form.pic': "",
    //   is_upload: false
    // })
  },
  getData() {
    app._getNetWork({
      url: app.getNetAddresss('plugin.third-logistics.frontend.modules.scan.controllers.validate.index'),
      data: { express_sn : this.data.express_sn },
      success: ({data}) => {
        if(data.result) {
          this.setData({
            deduct_love: data.data.deduct_love,
            express_sn: data.data.express_sn,
            buy_button: data.data.buy_button
          })
        }else {
          wx.showToast({
            icon: 'none',
            title: data.msg,
            duration: 1500
          });
        }
      },
      fail: function (res) {
        console.log(res);
      }
    })
  },
  async confirm() {
    app._postNetWork({
      url: app.getNetAddresss('plugin.third-logistics.frontend.modules.scan.controllers.confirm.index'),
      data: { 
        express_sn : this.data.express_sn,
        image_url: this.data.imgList.length ? this.data.imgList[0] : "" 
      },
      success: ({data}) => {
        if(data.result) {
          this.setData({
            signedShow: true
          })
        }else {
          if(data.data.love == 1) {
            this.setData({
              overlayShow: true
            })
          }else {
            wx.showToast({
              icon: 'none',
              title: data.msg,
              duration: 1500
            });
          }
        }
      },
      fail: function (res) {
        console.log(res);
      }
    })
  },
})